<?php 
	namespace app\data\model;

	use think\Model;

	/**
	* 商品属性模型
	*/
	class ShopGoodsAttr extends Model
	{
		/**
		 * 关联模型
		 * @return [type] [description]
		 */
		public function attr()
		{
			return $this->belongsTo('ShopCates','id');
		}

		/**
		 * 根据商品获取属性值
		 * @return [type] [description]
		 */
		public function all_goods_attr($gid)
		{
			return $this->where('goods_id',$gid)->select();
		}

		/**
		 * 删除数据
		 * @param  [type] $id [description]
		 * @return [type]     [description]
		 */
		public function del($id)
		{
			return $this->where('id',$id)->delete();
		}

		/**
		 * 根据商品id属性id获取信息
		 * @param  [type] $gid     [description]
		 * @param  [type] $attr_id [description]
		 * @return [type]          [description]
		 */
		public function goods_attr($gid,$attr_id)
		{
			return $this->where('goods_id',$gid)->where('attr_id',$attr_id)->find();
		}
	}